package main.od;

import java.util.Arrays;
import java.util.Scanner;

public class GreedyMerchant {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        int days = Integer.parseInt(sc.nextLine());
        int[] maxHoldArr = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[][] itemPriceArr = new int[num][days];
        int maxProfit = 0;
        for (int i = 0;i < num;i++){
            for (int j = 0;j < days;j++){
                itemPriceArr[i][j] = sc.nextInt();
            }
        }
        for (int i = 0;i < num;i++){
            for (int j = 0;j < days -1;j++){
                int purchasePrice = itemPriceArr[i][j];
                int sellingPrice = itemPriceArr[i][j+1];
                if (sellingPrice > purchasePrice){
                    maxProfit += (sellingPrice - purchasePrice) * maxHoldArr[i];
                }
            }
        }
        System.out.println("the max profit is " + maxProfit);
    }
}
